<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	
	Calendar calendar = Calendar.getInstance();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	calendar.setTime(new Date());
	String date2 = dateFormat.format(calendar.getTime());
	
	calendar.add(Calendar.HOUR, -1);
	String date1 = dateFormat.format(calendar.getTime());
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>历史数据</title>
	<meta name="viewport"  content="width=device-width, initial-scale=1">
	<link rel="stylesheet" type="text/css" href="${path}/resource/plugins/bootstrap/css/bootstrap.min.css">
  	<link rel="stylesheet" type="text/css" href="${path}/resource/css/ysrmain.css">
	<link rel="stylesheet" href="${path}/resource/css/gzfx.css">
	<link rel="stylesheet" type="text/css" href="${path}/resource/plugins/date/bootstrap-datetimepicker.min.css">
	<script src="${path}/resource/plugins/jQuery/jquery-2.2.3.min.js"></script>
	<script type="text/javascript" src="${path}/resource/plugins/bootstrap/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="${path}/resource/js/echarts.min.js"></script>
	<script src="${path}/resource/plugins/date/bootstrap-datetimepicker.min.js" charset="UTF-8"></script>
	<script src="${path}/resource/plugins/date/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>

	<style type="text/css">
		.right-content{
			background: none;
		   	border:none;
		    box-shadow: none;
		}
		.anchorBL{display:none;}
		/* .color-m1 {
		    color: #20FCFF;
		} */
		.foot-div1>div,.foot-div2>div{    
			display: table-cell;
    		vertical-align: middle;
    		text-align: center;
    		font-size: 3.5rem;
    	}		
		.foot-div3{;width:calc(100% + 15px)}
		.foot-div3>div{display:table;height:33.333%;text-align:center;width:100%}
		.foot-table-cell{display:table-cell;text-align:center;vertical-align: middle;color:#fff;font-size:1.6rem}
		/*图表全屏*/
		.main-data{height: 100%}
		.right-ul{height: 100%}
		.echats-div{height: 100%;border: 1px solid #337ab7;box-shadow: 0px 0px 8px #3399b7;border-top-right-radius: 5px;border-top-left-radius: 5px;}
		.time-input2{border: 1px solid #337ab7;}
	</style>
</head>
<body>
	<!-- 头部 -->
	<!-- 开始 -->
	<jsp:include page="top_nav.jsp"></jsp:include>
	<!-- 头部结束 -->
    <!-- 右侧内容区域 -->
    <!-- 右侧内容区域 -->
    <div class="right-content container-fluid ">
    	<div class="row">
    		<!-- 主要图表区域 -->
	    	<div class="main-data col-xs-9">
	    		<!--头部nav-->
	    		<div class="row right-nav">
	    			<div class=" center" style="padding-right:40px">
	    				<a class="color-m1" href="${path}/manage/redirect/allEquip/allEquipList">
	    					<img src="${path}/resource/images/back3.png">
	    				</a>
	    			</div>
	    			<div class=" center nav-hover">
	    				<a class="color-m1" href="${path}/manage/redirect/allEquip/nowEquip?serialNum=${serialNum}">
	    				<img src="${path}/resource/images/sssj3.png">
	    				运行状态
	    				</a>
	    			</div>
	    			<div class=" center nav-hover">
	    				<a class="color-m1" href="${path}/manage/redirect/allEquip/faultAnalysis?serialNum=${serialNum}">
	    				<img src="${path}/resource/images/gzfx3.png">
	    				故障分析
	    				</a>
	    			</div>
	    			<div class=" center nav-hover">
	    				<a class="color-m1" href="${path}/manage/redirect/allEquip/energyEfficiency?serialNum=${serialNum}">
	    				<img src="${path}/resource/images/nxgl3.png">
	    				能效分析
	    				</a>
	    			</div>
	    			<div class=" center nav-hover">
	    				<a class="color-m1" href="${path}/manage/redirect/allEquip/healthControl?serialNum=${serialNum}">
	    				<img src="${path}/resource/images/jkgl3.png">
	    				健康管理
	    				</a>
	    			</div>
	    			<div class=" center nav-select">
	    				<a class="color-m2" href="${path}/manage/redirect/allEquip/historyEquip?serialNum=${serialNum}">
	    				<img src="${path}/resource/images/lssj2.png">
	    				历史数据
	    				</a>
	    			</div>
	    			
	    			<div class=" right nav-over padding-r-1">	    				
	    				<div class="color-w">当前设备:${serialNum}</div>
	    			</div>
	    			
	    		</div>
	    		<!-- 主图表 -->
	    		<div class="main-img">
	    			<div class="times-input" style="height:7%;padding:8px 15px">
	    				<input onChange="dateChange();" type="text" readonly="readonly"  data-link-field="dtp_input2" placeholder="请选择开始日期" class="form_date time-input2" id="datetimepicker1" data-date-format="yyyy/mm/dd hh:ii">
	    				<span class=" span-date"><span class="glyphicon glyphicon-calendar"></span></span>	
			     		<input onChange="dateChange();" type="text" readonly="readonly"  data-link-field="dtp_input2" placeholder="请选择结束日期" class="form_date time-input2" id="datetimepicker2" data-date-format="yyyy/mm/dd hh:ii ">
			     		<span class=" span-date"><span class="glyphicon glyphicon-calendar"></span></span>
			     		<!-- <select id="chooseEcharts" class="time-input2">
				    		<option value="VAEcharts">电压电流数据</option>
				    		<option value="RHWEcharts">转速频率功率数据</option>
				    		<option value="01Echarts">开关量数据</option>
				    	</select> -->
	    			</div>
	    			<div class="col-xs-6 " style="height: 41%">
	    				<div class="echats-div">
			    			<div class="point foot-name">输入功率与开关状态</div>
		    				<div style="width:100%;height:100%;display:inline-block;height: calc(100% - 25px);">
								
								<div id="VAEcharts" style="width: 100%; height: 90%; float: left;"></div>
								
							</div>
						</div>
					</div>
					<div class="col-xs-6 " style="height: 41%">
						<div class="echats-div">
			    			<div class="point foot-name">使能状态</div>
		    				<div style="width:100%;height:100%;display:inline-block;height: calc(100% - 25px);">
								
								<div id="RHWEcharts" style="width: 100%; height: 90%; float: left;"></div>
								
							</div>
						</div>
					</div>
					<div class="col-xs-12 " style="height: 50%;margin-top: 1%">
						<div class="echats-div">
			    			<div class="point foot-name">风机与断路器状态</div>
		    				<div style="width:100%;height:100%;display:inline-block;height: calc(100% - 25px);">						
								<div id="01Echarts" style="width: 100%; height: 90%; float: left;"></div>	
								
							</div>
						</div>
					</div>
	    				
	    				
	    			    				    			
	    		</div>
	    	</div>
	    	<!-- 右侧列表 -->
	    	<div class=" col-xs-3 right-ul center">
	    		<div class="right-list">
	    			<div class="center">
			    		<div class="input-group search-input ">
					      <input id="require" type="text"  class="form-control float-r search back-m1 color-w">
					      <span class="input-group-btn">
					        <button class="btn btn-default search-btn" type="button" onclick="search();"></button>
					      </span>
						</div>
						<div class="left table-head color-w">
							<span >序列号</span><span class="float-r">运行状态</span>
						</div>
						<div class="ul-div">
	
							<table id="listtable" class="table table-striped color-w">
							  
							  <tr>
							  	<td class="left"><a class="color-w" href="<%=path%>/manage/redirect/allEquip/faultAnalysis?serialNum=0181413C">0181413C</a></td>
							  	<td class="right">正常</td>
							  </tr>
							
							  
							 
							</table>
						</div>
					</div>
	    		</div>
	    	</div>
	    	
	    	<!-- 底部表格 -->
	    	<!-- <div class="foot-img">
	    		<div class="col-xs-4 margin-t-1 ">
	    			
	    			<div class="foot-div1 back-a"> 
	    				<div id="echarts2" style="width: 50%; height: 100%;float:left"></div>
	    				<div id="echarts3" style="width: 50%; height: 100%;float:left"></div>
	    				<div class="color-w count-time">
		    				<span>总时长:</span>
		    				<span id="zongshichang" class="color-m1">0</span><span>小时</span>
	    				</div>
	    			</div> 
	    		</div>
	    		<div class="col-xs-4 margin-t-1 padding-l">
	    			<div class="foot-div2 back-a color-w"> 
	    				<strong style="float:left"> 75% </strong>
	    				<div class="progress" style="height:25%">

						  <div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%">
						    <span class="sr-only">75% Complete (success)</span>
						  </div>
						</div>
						<strong style="float:left"> 30% </strong>
						<div class="progress" style="height:25%">
						  <div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="width: 30%">
						    <span class="sr-only">30% Complete</span>
						  </div>
						</div>
						<div class="color-w">
		    				<span>故障总数:</span>
		    				<span id="zongguzhang" class="color-m1">0</span><span>次</span>
	    				</div>
						
	    			</div> 
	    		</div>
	    		<div class="col-xs-4 margin-t-1 ">
	    			<div class="foot-div3 back-a">
	    				<div>
		    				<div class="foot-table-cell">
		    					<div>交流断路器动作次数:<span id="bottombreakerstate" class="color-m1">0</span></div>
		    				</div>
	    				</div>
	    				<div>
		    				<div class="foot-table-cell">
		    					<div>风机动作次数:<span id="bottomfanstart" class="color-m1">0</span></div>
		    				</div>
	    				</div>
	    				<div>
		    				<div class="foot-table-cell">
		    					<div>变频器正常运行截止时间:<span id="bottomtime" class="color-m1">0</span></div>
		    				</div>
	    				</div>
	    			</div>
	    		</div>
	    	</div> -->
    	</div>
    </div>
	



	
</body>
<script type="text/javascript" src="${path}/resource/js/webSocketConf.js"></script>	
<!-- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script> -->
<script type="text/javascript">
	//输入功率与开关状态
	var GLKGoption = {
		    tooltip : {
		        trigger: 'axis'
		    },
		    legend: {
		        top: 0,
		        right: 0,
		        textStyle: {
		        	color: '#fff'
		        },
		        data:['输入功率','电抗器温控开关']
		    },
		    grid: {
		    	top: '25%',
		        left: '3%',
		        right: '4%',
		        bottom: '3%',
		        containLabel: true
		    },
		    xAxis : [
		        {
		            type : 'category',
		            boundaryGap : false,
		            axisLine: {
		                lineStyle: {
		                    color: '#3a8fd8'
		                }
		            },
		            axisTick: {
		                inside: true,
		                length: 10,
		                lineStyle: {
		                    color: '#3a8fd8'
		                }
		            },
		            axisLabel: {
		                textStyle: {
		                    color: '#fff'
		                }
		            },
		            data : ['12:00','12:10','12:20','12:30','12:40','12:50']
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            axisLine: {
		                show: false
		            },
		            axisTick: {
		                show: false  
		            },
		            axisLabel: {
		                textStyle: {
		                    color: '#fff'
		                }
		            },
		            splitLine: {
		                lineStyle: {
		                    color: '#3a8fd8',
		                    type: 'dashed'
		                }
		            }
		        }
		    ],
		    series : [
		        {
		            name:'输入功率',
		            type:'line',
		            stack: '总量',
		            symbol: 'circle',
		            symbolSize: 1,
		            lineStyle: {
		                normal : {
		                    color : '#48f2ff'
		                }
		            },
		            itemStyle: {
		                normal: {
		                    color: '#48f2ff'  
		                }
		            },
		            areaStyle: {
		                normal: {
		                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, 
		                        [{
		                          offset: 0, color: '#48f2ff' // 0% 处的颜色
		                        }, {
		                          offset: 1, color: '#fff' // 100% 处的颜色
		                        }], false)
		                }
		            },
		            markPoint: {
		                //symbol: 'image://https://www.baidu.com/img/bd_logo1.png',
		                symbolSize: 30,
		                label: {
		                    normal: {
		                        textStyle: {
		                            fontSize: 10
		                        }
		                    }
		                },
		                itemStyle: {
		                    normal: {
		                        color: '#48f2ff'
		                    },
		                },
		                data: [
		                    {name: '最大值', type: 'max'}
		                ]
		            },
		            data:[120, 132, 230, 132, 90, 230]
		        },
// 		        {
// 		            name:'电抗器温控开关',
// 		            type:'line',
// 		            stack: '总量',
// 		            symbol: 'circle',
// 		            symbolSize: 1,
// 		            lineStyle: {
// 		                normal: {
// 		                    color: '#3a8fd8'
// 		                }  
// 		            },
// 		            itemStyle: {
// 		                normal: {
// 		                    color: '#3a8fd8'
// 		                },
// 		            },
// 		            areaStyle: {
// 		                normal: {
// 		                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, 
// 		                        [{
// 		                          offset: 0, color: '#3a8fd8' // 0% 处的颜色
// 		                        }, {
// 		                          offset: 1, color: '#fff' // 100% 处的颜色
// 		                        }], false)
// 		                }
// 		            },
// 		            markPoint: {
// 		                symbolSize: 30,
// 		                label: {
// 		                    normal: {
// 		                        textStyle: {
// 		                            fontSize: 10
// 		                        }
// 		                    }
// 		                },
// 		                itemStyle: {
// 		                    normal: {
// 		                        color: '#3a8fd8'
// 		                    },
// 		                },
// 		                data: [
// 		                    {name: '最大值', type: 'max'}
// 		                ]
// 		            },
// 		            data:[220, 182, 191, 234, 290, 330]
// 		        }
		    ]
		};
	
	//使能状态
	var SNZToption = {
	    tooltip : {
	        trigger: 'axis'
	    },
	    legend: {
	        top: 0,
	        right: 0, 
	        textStyle: {
	        	color: '#fff'
	        },
	        data:['逆变使能','四象限使能']
	    },
	    grid: {
	    	top: '25%',
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
	            boundaryGap : false,
	            axisLine: {
	                lineStyle: {
	                    color: '#3a8fd8'
	                }
	            },
	            axisTick: {
	                inside: true,
	                length: 10,
	                lineStyle: {
	                    color: '#3a8fd8'
	                }
	            },
	            axisLabel: {
	                textStyle: {
	                    color: '#fff'
	                }
	            },
	            data : ['12:00','12:10','12:20','12:30','12:40','12:50']
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            axisLine: {
	                show: false
	            },
	            axisTick: {
	                show: false  
	            },
	            axisLabel: {
	                textStyle: {
	                    color: '#fff'
	                }
	            },
	            splitLine: {
	                lineStyle: {
	                    color: '#3a8fd8',
	                    type: 'dashed'
	                }
	            }
	        }
	    ],
	    series : [
	        {
	            name:'逆变使能',
	            type:'line',
	            stack: '总量',
	            symbol: 'circle',
	            symbolSize: 1,
	            lineStyle: {
	                normal : {
	                    color : '#48f2ff'
	                }
	            },
	            itemStyle: {
	                normal: {
	                    color: '#48f2ff'  
	                },
	                emphasis: {
	                    color: 'red',
	                    shadowColor: 'red',
	                    shadowBlur: 10
	                }
	            },
	            markPoint: {
	                symbol: 'circle',
	                symbolSize: 10,
	                label: {
	                    normal: {
	                        show: false
	                    }
	                },
	                itemStyle: {
	                    normal: {
	                        color: 'red',
	                        shadowColor: 'red',
	                        shadowBlur: 10
	                    },
	                },
	                data: [
	                    {name: '最大值', type: 'max'},
	                    {name: '最小值', type: 'min'}
	                ]
	            },
	            data:[120, 132, 101, 134, 90, 230]
	        },
	        {
	            name:'四象限使能',
	            type:'line',
	            stack: '总量',
	            symbol: 'circle',
	            symbolSize: 1,
	            lineStyle: {
	                normal: {
	                    color: '#3a8fd8'
	                }  
	            },
	            itemStyle: {
	                normal: {
	                    color: '#3a8fd8'
	                },
	                emphasis: {
	                    color: 'green',
	                    shadowColor: 'green',
	                    shadowBlur: 10
	                }
	            },
	            markPoint: {
	                symbol: 'circle',
	                symbolSize: 10,
	                label: {
	                    normal: {
	                        show: false
	                    }
	                },
	                itemStyle: {
	                    normal: {
	                        color: 'green',
	                        shadowColor: 'green',
	                        shadowBlur: 10
	                    },
	                },
	                data: [
	                    {name: '最大值', type: 'max'},
	                    {name: '最小值', type: 'min'}
	                ]
	            },
	            data:[220, 182, 191, 234, 290, 330]
	        }
	    ]
	};
	
	//风机与断路器状态
	var FJDLoption = {
	    tooltip : {
	        trigger: 'axis'
	    },
	    legend: {
	        top: 0,
	        right: 0, 
	        textStyle: {
	        	color: '#fff'
	        },
	        data:['风机启动状态', '断路器状态', '直流断路器状态', 'MPPT启动', '充电接触器命令']
	    },
	    grid: {
	    	top: '25%',
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis : [
	        {
	            type : 'category',
	            boundaryGap : false,
	            //offset: 20,
	            axisLine: {
	                lineStyle: {
	                    color: '#3a8fd8'
	                }
	            },
	            axisTick: {
	                inside: true,
	                length: 10,
	                lineStyle: {
	                    color: '#3a8fd8'
	                }
	            },
	            axisLabel: {
	                textStyle: {
	                    color: '#fff'
	                }
	            },
	            data : ['12:00','12:05','12:10','12:15','12:20','12:25','12:30','12:35','12:40','12:45','12:50']
	        }
	    ],
	    yAxis : [
	        {
	            type : 'value',
	            offset: 10,
	            
	            scale: true,
	            axisLine: {
	                show: false
	            },
	            axisTick: {
	                show: false  
	            },
	            axisLabel: {
	                textStyle: {
	                    color: '#fff'
	                }
	            },
	            splitLine: {
	                lineStyle: {
	                    color: '#3a8fd8',
	                    type: 'dashed'
	                }
	            }
	        }
	    ],
	    color: ['#3a8fd8', '#48f2ff'],
	    series : [
	        {
	            name:'风机启动状态',
	            type:'line',
	            barWidth: 10,
	            barGap: 0,
	            data:[320, 332, 301,0,0,0,0,0, 334, 390, 330]
	        },
	        {
	            name:'断路器状态',
	            type:'line',
	            barWidth: 10,
	            barGap: 0,
	            data:[120, 132, 101, 134, 90,0,0,0,0,0, 230]
	        },
	        {
	            name:'直流断路器状态',
	            type:'line',
	            barWidth: 10,
	            barGap: 0,
	            data:[120, 132, 101,0,0,0,0,0, 134, 90, 230]
	        },
	        {
	            name:'MPPT启动',
	            type:'line',
	            barWidth: 10,
	            barGap: 0,
	            data:[120, 132,0,0,0,0,0, 101, 134, 90, 230]
	        },
	        {
	            name:'充电接触器命令',
	            type:'line',
	            barWidth: 10,
	            barGap: 0,
	            data:[120, 0,0,0,0,0,132, 101, 134, 90, 230]
	        },
	    ]
	};
</script>
<script type="text/javascript">

	var date1 = "<%=date1%>";
	var date2 = "<%=date2%>";
	
	$(function(){
		$(".img-qbsb").parent().css({"color":"#82d1e8","text-shadow":" 0px 0px 10px #b7d6df"});
		$(".img-qbsb").parent().parent().addClass("dl-active");
		$(".img-qbsb").attr("src","${path}/resource/images/qbsb2.png"); 
		/*时间组件 */
		$(".span-date").click(function(){
			$(this).prev().focus();
		})
		
		//test环境
		//search();
		
		//jiekou('2016/09/05 14:46:11', '2016/09/05 19:46:11');
		//jiekou(date1, date2);
		newJieKou(date1, date2);
		
// 		secondhistDataRuntime();
// 		secondhistDataContribution();
// 		secondhistDataLocation();
		
	})
	
	$('.form_date').datetimepicker({
	    language:  'zh-CN',
	    autoclose: true,		
	    minuteStep:1,
		format: 'yyyy/mm/dd hh:ii'
	});
	//限制结束时间不能大于开始时间
	$('#datetimepicker1').datetimepicker().on('changeDate', function(e){
		var currentTime = e.date;
		$('#datetimepicker2').datetimepicker('setStartDate', currentTime);
		var endCurrentTime = e.date;
		endCurrentTime.setDate(endCurrentTime.getDate()+7); 
		$('#datetimepicker2').datetimepicker('setEndDate', endCurrentTime);
	});	
	$('#datetimepicker2').datetimepicker().on('changeDate', function(e){
		var currentTime = e.date;
		$('#datetimepicker1').datetimepicker('setEndDate', currentTime);
		var startCurrentTime = e.date;
		startCurrentTime.setDate(startCurrentTime.getDate()-7); 
		$('#datetimepicker1').datetimepicker('setStartDate', startCurrentTime);
	});
	
	function dateChange() {
		var startTime,endTime;
		if($('#datetimepicker1').val() != null && $('#datetimepicker1').val() != undefined && $('#datetimepicker1').val() != ''
			&& $('#datetimepicker2').val() != null && $('#datetimepicker2').val() != undefined && $('#datetimepicker2').val() != ''
		) {
			startTime = $('#datetimepicker1').val() + ':00';
			endTime = $('#datetimepicker2').val() + ':59';
			
			newJieKou(startTime, endTime);
		}
	}
	
	var VAEcharts = echarts.init(document.getElementById("VAEcharts"));
	VAEcharts.setOption(GLKGoption);
	var RHWEcharts = echarts.init(document.getElementById("RHWEcharts"));
	RHWEcharts.setOption(SNZToption);
	var KGEcharts = echarts.init(document.getElementById("01Echarts"));
	KGEcharts.setOption(FJDLoption);
	
	function newJieKou(startTime, endTime) {
		var Xdata = [];
		var GLKGoptionData = [], SNZToptionData = [], FJDLoptionData = [];
		
		$.ajax({
			type : 'POST',
			url : '<%=path%>/manage/secondhistData',
			data : {
				startTime : startTime,
				endTime : endTime,
				serialNum : '${serialNum}'
			},
			dataType : 'json',
			async : false,
			success : function(result) {
				if(result.status == 'OK') {
					var data = result.data;
					Xdata = eval("(" + data.timeStamp + ")");
					
					var inputpower = eval("(" + data.inputpower + ")"); //输入功率
					
					var contravariantenable = eval("(" + data.contravariantenable + ")"); //逆变综合使能
					var fourquadrantenable = eval("(" + data.fourquadrantenable + ")"); //四象限综合使能
					
					var fanstate = eval("(" + data.fanstate + ")"); //风机状态
					var breakerstate = eval("(" + data.breakerstate + ")"); //断路器状态
					var dccircuitbreaker = eval("(" + data.dccircuitbreaker + ")"); //直流断路器状态
					var mpptstartstate = eval("(" + data.mpptstartstate + ")"); //MPPT启动
					var chargeorder = eval("(" + data.chargeorder + ")"); //充电命令
					
					GLKGoption.xAxis[0].data = Xdata;
					SNZToption.xAxis[0].data = Xdata;
					FJDLoption.xAxis[0].data = Xdata;
					
					GLKGoption.series[0].data = inputpower;
					//GLKGoptionData.series[1].data = inputpower;
					
					SNZToption.series[0].data = contravariantenable;
					SNZToption.series[1].data = fourquadrantenable;
					
					FJDLoption.series[0].data = fanstate;
					FJDLoption.series[1].data = breakerstate;
					FJDLoption.series[2].data = dccircuitbreaker;
					FJDLoption.series[3].data = mpptstartstate;
					FJDLoption.series[4].data = chargeorder;
					
					VAEcharts.setOption(GLKGoption);
					RHWEcharts.setOption(SNZToption);
					KGEcharts.setOption(FJDLoption);
				}
			},
			error : function() {
				//inittest();
			}
		});
	}
	
	function jiekou(startTime, endTime) {
		var totallegend1 = ['输入电流有效值', '输出电流有效值', '中间电流有效值', '中间电压有效值', '网压有效值'];
		var totaldata1 = [];
		
		var totallegend2 = ['实际频率', '输入功率', '格力转速给定'];
		var totaldata2 = [];
		
		var totallegend3 = ['断路器状态', '充电命令', '逆变综合使能', '直流断路器状态', '风机状态', '故障灯', '四象限综合使能', '格力启机', 'MPPT启动', '反向充电', '运行灯', '启四象限', '启逆变'];
		var totaldata3 = [];
		
		$.ajax({
			type : 'POST',
			url : '<%=path%>/manage/secondhistData',
			data : {
				startTime : startTime,
				endTime : endTime,
				serialNum : '${serialNum}'
			},
			dataType : 'json',
			async : false,
			success : function(result) {
				console.log(result);
				if(result.status == 'OK') {
					var xData = [];
					var currentinput=[],currentoutput=[],
					intermediatecurrent=[],intermediatevot=[],netvoltage=[],
					actualfreq=[],inputpower=[],theoreticspeed=[];
					
					var data = result.data;
					xData = eval("(" + data.timeStamp + ")");
					
					currentinput = eval("(" + data.currentinput + ")"); //输入电流有效值
					currentoutput = eval("(" + data.currentoutput + ")"); //输出电流有效值
					intermediatecurrent = eval("(" + data.greestartingstate + ")"); //中间电流有效值
					intermediatevot = eval("(" + data.intermediatevot + ")"); //中间电压有效值
					netvoltage = eval("(" + data.netvoltage + ")"); //网压有效值
					
					actualfreq = eval("(" + data.actualfreq + ")"); //实际频率
					inputpower = eval("(" + data.inputpower + ")"); //输入功率
					theoreticspeed = eval("(" + data.theoreticspeed + ")"); //格力转速给定
					
					var breakerstate = eval("(" + data.breakerstate + ")"); //断路器状态
					var chargeorder = eval("(" + data.chargeorder + ")"); //充电命令
					var contravariantenable = eval("(" + data.contravariantenable + ")"); //逆变综合使能
					var dccircuitbreaker = eval("(" + data.dccircuitbreaker + ")"); //直流断路器状态
					var fanstate = eval("(" + data.fanstate + ")"); //风机状态
					var faultlight = eval("(" + data.faultlight + ")"); //故障灯
					var fourquadrantenable = eval("(" + data.fourquadrantenable + ")"); //四象限综合使能
					var greestartingstate = eval("(" + data.greestartingstate + ")"); //格力启机
					var mpptstartstate = eval("(" + data.mpptstartstate + ")"); //MPPT启动
					var reversecharg = eval("(" + data.reversecharg + ")"); //反向充电
					var runninglight = eval("(" + data.runninglight + ")"); //运行灯
					var startfourquadrant = eval("(" + data.startfourquadrant + ")"); //启四象限
					var startinverter = eval("(" + data.startinverter + ")"); //启逆变
					//电压电流数据
					totaldata1.push({
			            name:'输入电流有效值',
			            type:'line',
			            yAxisIndex:0,
			            data:currentinput
			        },{
			            name:'输出电流有效值',
			            type:'line',
			            yAxisIndex:0,
			            data:currentoutput
			        },{
			            name:'中间电流有效值',
			            type:'line',
			            yAxisIndex:0,
			            data:greestartingstate
			        },{
			            name:'中间电压有效值',
			            type:'line',
			            yAxisIndex:0,
			            data:intermediatevot
			        },{
			            name:'网压有效值',
			            type:'line',
			            yAxisIndex:0,
			            data:netvoltage
			        });
					//转速频率数据
					totaldata2.push({
			            name:'实际频率',
			            type:'line',
			            yAxisIndex:0,
			            data:actualfreq
			        },{
			            name:'输入功率',
			            type:'line',
			            yAxisIndex:0,
			            data:inputpower
			        },{
			            name:'格力转速给定',
			            type:'line',
			            yAxisIndex:0,
			            data:theoreticspeed
			        });
					//开关量数据
					totaldata3.push({
			            name:'断路器状态',
			            type:'line',
			            yAxisIndex:0,
			            data: breakerstate
			        },{
			            name:'充电命令',
			            type:'line',
			            yAxisIndex:0,
			            data: chargeorder
			        },{
			            name:'逆变综合使能',
			            type:'line',
			            yAxisIndex:0,
			            data: contravariantenable
			        },{
			            name:'直流断路器状态',
			            type:'line',
			            yAxisIndex:0,
			            data: dccircuitbreaker
			        },{
			            name:'风机状态',
			            type:'line',
			            yAxisIndex:0,
			            data: fanstate
			        },{
			            name:'故障灯',
			            type:'line',
			            yAxisIndex:0,
			            data: faultlight
			        },{
			            name:'四象限综合使能',
			            type:'line',
			            yAxisIndex:0,
			            data: fourquadrantenable
			        },{
			            name:'格力启机',
			            type:'line',
			            yAxisIndex:0,
			            data: greestartingstate
			        },{
			            name:'MPPT启动',
			            type:'line',
			            yAxisIndex:0,
			            data: mpptstartstate
			        },{
			            name:'反向充电',
			            type:'line',
			            yAxisIndex:0,
			            data: reversecharg
			        },{
			            name:'运行灯',
			            type:'line',
			            yAxisIndex:0,
			            data: runninglight
			        },{
			            name:'启四象限',
			            type:'line',
			            yAxisIndex:0,
			            data: startfourquadrant
			        },{
			            name:'启逆变',
			            type:'line',
			            yAxisIndex:0,
			            data: startinverter
			        });
					
// 					initLineEcharts("VAEcharts",VAEcharts,totallegend1,xData,totaldata1);
// 					initLineEcharts("RHWEcharts",RHWEcharts,totallegend2,xData,totaldata2);
// 					initLineEcharts("01Echarts",KGEcharts,totallegend3,xData,totaldata3);
// 					$('#chooseEcharts').val('VAEcharts');
// 					$("#VAEcharts").css("display", "block");
// 					$("#RHWEcharts").css("display", "none");
// 					$("#01Echarts").css("display", "none");
				} else {
					inittest();
				}
			},
			error : function() {
				inittest();
			}
		});
	}
	
	//运行总时长
// 	function secondhistDataRuntime(){
// 		$.ajax({
<%-- 			url : '<%=path%>/manage/secondhistDataRuntime', --%>
// 			data : { serialNum : '${serialNum}' },
// 	        type : 'post',
// 	        dataType : 'json',
// 	        async : false,	        
// 	        success : function(result) {
// 	        	$('#zongshichang').text(result.data);
// 			},			
// 			error : function(result) {
// 				console.log('error');
// 			}
// 		});	
// 	}
	//社会贡献值
// 	function secondhistDataContribution(){
// 		$.ajax({
<%-- 			url : '<%=path%>/manage/secondhistDataErrorCount', --%>
// 			data : { serialNum : '${serialNum}' },
// 	        type : 'post',
// 	        dataType : 'json',
// 	        async : false,	        
// 	        success : function(result) {
// 	        	if(result.status == 'OK') {
// 	        		$('#zongguzhang').text(result.data);
// 	        	}
// 			},			
// 			error : function(result) {
// 				console.error('error');
// 			}
// 		});	
// 		$.ajax({
<%-- 			url : '<%=path%>/manage/secondhistDataContribution', --%>
// 			data : { serialNum : '${serialNum}' },
// 	        type : 'post',
// 	        dataType : 'json',
// 	        async : false,	        
// 	        success : function(result) {
// 	        	var electric = result.data.electSave.toString();
// 				if(electric.indexOf(".") > 0) {
// 					electric = electric.substring(0,7);
// 				} else {
// 					electric = electric.substring(0,6);
// 				}
// 				$('#electric').text(electric);
// 				var co2 = result.data.coSave.toString();
// 				if(co2.indexOf(".") > 0) {
// 					co2 = co2.substring(0,7);
// 				} else {
// 					co2 = co2.substring(0,6);
// 				}
// 				$('#co2').text(co2);
// 				var coal = result.data.coalSave.toString();
// 				if(coal.indexOf(".") > 0) {
// 					coal = coal.substring(0,7);
// 				} else {
// 					coal = coal.substring(0,6);
// 				}
// 				$('#coal').text(coal);
// 			},			
// 			error : function(result) {
// 				console.error('error');
// 			}
// 		});	
// 	}
	//位置
// 	function secondhistDataLocation(){
// 		$.ajax({
// 			type : 'POST',
<%-- 			url : '<%=path%>/manage/secondliveData', --%>
// 			data : {
// 				serialNum : '${serialNum}'
// 			},
// 			dataType : 'json',
// 			async : false,
// 			success : function(result) {
// 				console.log(result);
// 				if(result.status == 'OK') {
// 					var devInfo = eval("(" + result.data.devInfo + ")")[0];
// 					$('#bottombreakerstate').text(devInfo.breakerstate);
// 					$('#bottomfanstart').text(devInfo.fanstart);
// 					if(devInfo.operationDate != null && devInfo.operationDate != undefined && devInfo.operationDate != "") {
// 						var year = parseInt(devInfo.operationDate.substring(0,4)) + 3;
// 						$('#bottomtime').text(year + devInfo.operationDate.substring(4));
// 					}
// 				} else {
// 					//alert("系统错误！");
// 				}
// 			},
// 			error : function() {
// 				//alert("系统错误！");
// 			}
// 		})
// 		$.ajax({
<%-- 			url : '<%=path%>/manage/secondhistDataLocation', --%>
// 			data : { serialNum : '${serialNum}' },
// 	        type : 'post',
// 	        dataType : 'json',
// 	        async : false,	        
// 	        success : function(result) {
// 	        	var geoCoord = eval("(" + result.data.geoCoord + ")");
// 	    		initmap(geoCoord[0], geoCoord[1]);
// 			},			
// 			error : function(result) {
// 				console.error('error');
// 			}
// 		});	
// 	}
	
	//加载右侧列表
	function search() {
		$.ajax({
			type : 'POST',
			url : '<%=path%>/manage/seconddevTotal',
			data : {
				livedata : livedata,
				require : $("#require").val()
			},
			dataType : 'json',
			async : false,
			success : function(result) {
				if(result.status == "OK") {
					$('#listtable').text('');
					//var html = "<tr><th>变频器序列号</th><th>安装位置</th><th>投运时间</th><th>工作状态</th></tr>";
					var html = "";
					$.each(result.data, function(i){
						var href = "<%=path%>/manage/redirect/allEquip/nowEquip?serialNum="+result.data[i].serialNum;
						html += '<tr><td class="left"><a href='+href+'>'+result.data[i].serialNum +
								'</a></td><td class="right">'+result.data[i].state +'</td></tr>';
					});
					$('#listtable').append(html);
				}
			},
			error : function() {
				//alert("系统错误！");
			}
		})
	}
	
function initLineEcharts(domId,myEcharts,totallegend,xData,totaldata) {
	var yAxis = [{
            type : 'value',
            name : '',
            nameTextStyle : {
	    		color : '#fff'
	    	},
            axisLabel: {
	            textStyle: {
	                color: '#fff'
	            }
            }
    }];
	switch(domId) {
	case "VAEcharts" : yAxis[0].name = '电压(V)/电流(A)';break;//yAxis.push({name: '电压(V)/电流(A)',type: 'value'});break;
	case "RHWEcharts" : yAxis[0].name = '转速(r/min)/频率(Hz)/功率(kW)';break;//yAxis.push({name: '转速(r/min)/频率(Hz)/功率(kW)',type: 'value'});break;
	case "01Echarts" : yAxis[0].name = '开(1)/关(0)';yAxis[0].max = '2';break;//yAxis.push({name: '开(1)/关(0)',type: 'value', max : '2'});break;
	}
	myEcharts.setOption({
		    tooltip: {
		        trigger: 'axis'
		    },
		    legend: {
		        data:totallegend,
		        /*left: '25%'*/
		        x: 'center',
			    y: 'bottom',
			    textStyle : {
			    	color : '#fff'
			    }
		    },
		    grid: {
		    	top : '7%',
		        left: '3%',
		        right: '4%',
		        bottom: '10%',
		        containLabel: true
		    },
		    xAxis: {
		        type: 'category',
		        boundaryGap: false,
		        axisLabel: {
		            textStyle: {
		                color: '#fff'
		            }
	            },
		        data: xData
		    },
		    yAxis: yAxis,
		    dataZoom: [{
		        //type: 'inside',
		        show : true,
		        height : 12,
		        start: 35,
		        end: 65,
		        textStyle : {
		        	color : '#fff'
		        }
		    },{
		        type: 'inside',
		        start: 35,
		        end: 65
		    }],
		    series: totaldata
	});
}
function inittest() {
 	var myEcharts1 = echarts.init(document.getElementById("VAEcharts"));
	myEcharts1.setOption({
// 			title: {
// 		        text: ''
// 		    },
		    tooltip: {
		        trigger: 'axis'
		    },
		    legend: {
		        data:['输入功率','电抗器温控开关','逆变使能','四象限使能','MPPT启动' ,'断路器状态' , '直流断路器状态','风机启动状态','充电接触器命令','充电接触器状态'],
		        /*left: '25%'*/
		        x: 'center',
			    y: 'bottom'
		    },
		    grid: {
		        left: '3%',
		        right: '4%',
		        bottom: '10%',
		        containLabel: true
		    },
		  
		    xAxis: {
		        type: 'category',
		        boundaryGap: false,
		        data: ['11:44:22','11:44:23','11:44:24','11:44:25','11:44:26','11:44:27','11:44:28','11:44:29','11:44:30','11:44:31']
		    },
		    yAxis: [{
		    	//name: '输入功率（KW）',
		        type: 'value'
		    },{
		    	name: '输入功率（KW）',
		        type: 'value',
		        max: 20000,
           		min: 0,
		    }

		    ],
		    dataZoom: [{
		        type: 'inside',
		        start: 0,
		        end: 50
		    }],
		    series: [
		        {
		            name:'输入功率',
		            type:'line',
		            stack: '总量',
		            data:[120, 132, 101, 134, 90, 230, 210,123,123,122]
		        },
		        {
		            name:'电抗器温控开关',
		            type:'line',
		            stack: '总量',
		            data:[220, 182, 191, 234, 290, 330, 310,80,70,120]
		        },
		        {
		            name:'逆变使能',
		            type:'line',
		            stack: '总量',
		            data:[150, 232, 201, 154, 190, 330, 410,230,120,80]
		        },
		        {
		            name:'四象限使能',
		            type:'line',
		            stack: '总量',
		            data:[320, 332, 301, 334, 390, 330, 320,120,320,120]
		        },
		        {
		            name:'MPPT启动',
		            type:'line',
		            stack: '总量',
		            data:[820, 932, 901, 934, 1290, 1330, 1320,1230,1100,230]
		        },
		         {
		            name:'断路器状态',
		            type:'line',
		            stack: '总量',
		            data:[420, 132, 501, 534, 590, 330, 420,130,100,230]
		        },
		          {
		            name:'直流断路器状态',
		            type:'line',
		            stack: '总量',
		            data:[520, 432, 301, 534, 590, 350, 220,180,110,530]
		        },
		         {
		            name:'风机启动状态',
		            type:'line',
		            stack: '总量',
		            data:[820, 122, 501, 434, 490, 550, 420,190,510,230]
		        },
		        {
		            name:'充电接触器命令',
		            type:'line',
		            stack: '总量',
		            data:[250, 182, 801, 834, 890, 650, 620,890,810,830]
		        },
		          {
		            name:'充电接触器状态',
		            type:'line',
		            stack: '总量',
		            data:[650, 482, 301, 734, 790, 550, 520,190,110,30]
		        },
		    ]
	});
}
//选择不同主图表
$('#chooseEcharts').change(function(){
	if($(this).val() != "" && $(this).val() != null) {
		$("#VAEcharts").css("display", "none");
		$("#RHWEcharts").css("display", "none");
		$("#01Echarts").css("display", "none");
		$("#"+$(this).val()).css("display", "block");
	}
});
	
// var myEcharts2 = echarts.init(document.getElementById("echarts2"));

// 	myEcharts2.setOption({
// 			series : [ {
// 			name : "饼状图",
// 			//类型饼状图
// 			type : "pie",
// 			//半径
// 			radius : '90%',
// 		//	roseType : 'angle',
// 			itemStyle:{ 
//                 normal:{ 
//                     label:{ 
//                        show: true, 
//                        position : 'inside',
//                        formatter: '{d}%' ,
//                        textStyle :{
//                        		fontSize : 5
//                        }
//                     }, 
//                     labelLine :{show:false}
//                 } 
//             } ,
// 			data : [ {
// 				value : 400,
// 				name : ''
// 			}, {
// 				value : 100,
// 				name : ''
// 			}, {
// 				value : 200,
// 				name : ''
// 			}, {
// 				value : 100,
// 				name : ''
// 			}, {
// 				value : 200,
// 				name : ''
// 			} ]
// 		}]

// 	});



// var myEcharts3 = echarts.init(document.getElementById("echarts3"));
// 	myEcharts3.setOption({
// 		series : [ {
// 			name : "饼状图",
// 			//类型饼状图
// 			type : "pie",
// 			//半径
// 			radius : '100%',
// 			roseType : 'angle',
// 			itemStyle:{ 
//                 normal:{ 
//                     label:{ 
//                        show: true, 
//                        position : 'inside',
//                        formatter: '{d}%' ,
//                        textStyle :{
//                        		fontSize : 5
//                        }
//                     }, 
//                     labelLine :{show:false}
//                 } 
//             } ,
// 			data : [ {
// 				value : 400,
// 				name : ''
// 			}, {
// 				value : 335,
// 				name : ''
// 			}, {
// 				value : 310,
// 				name : ''
// 			}, {
// 				value : 274,
// 				name : ''
// 			}, {
// 				value : 235,
// 				name : ''
// 			} ]
// 		}]
	    
// 	})

	function initmap(longitude, latitude) { //经度，纬度
		// 百度地图API功能
		map = new BMap.Map("echarts5", {enableMapClick:false}); //构造底图时，关闭底图可点功能
		map.setMapType(BMAP_NORMAL_MAP); //设置默认为卫星图
		var point = new BMap.Point(longitude, latitude);
		map.centerAndZoom(point, 13);
		//map.setMinZoom(8);
		map.disableDragging(); //禁止拖拽
		map.disableScrollWheelZoom(); //禁用滚轮缩放
		//map.enableDragging(); //开启拖拽
		//map.enableScrollWheelZoom(); //允许滚轮缩放
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
	}
	
/*
	var myEcharts5 = echarts.init(document.getElementById("echarts5"));
	myEcharts5.setOption({
		tooltip: {
	        trigger: 'item',
	        formatter: "{a} <br/>{b}: {c} ({d}%)"
	    },
	    legend: {
	        orient: 'vertical',
	        x: 'right',
	        y: 'bottom',
	        data:['chrome','firefox','Safari']
	    },
		
	    series: [
	             {
	                 name:'故障分析',
	                 type:'pie',
	                 radius: ['50%', '70%'],       //内环半径，外环半径
	                 clockwise: false,
	                 avoidLabelOverlap: false,

	                 label: {
	                     normal: {
	                         show: false,
	                         position: 'center'
	                     },
	                     emphasis: {
	                         show: true,
	                         textStyle: {
	                             fontSize: '30',
	                             fontWeight: 'bold'
	                         }
	                     }
	                 },
	                 labelLine: {
	                     normal: {
	                         show: false
	                     }
	                 },
	                 data:[
	                     {value:1335, name:'chrome'},
	                     {value:310, name:'firefox'},
	                     {value:234, name:'Safari'},
	                    
	                 ]
	             }
	         ]
		
	});
	*/
//获取设备列表实时数据
	
	var webSocket2 = null;
    var livedata;
    if ("WebSocket" in window) {
		webSocket2 = new WebSocket(webSocketUrl);
		console.log("建立实时连接！");
	} else if ("MozWebSocket" in window) {
		webSocket2 = new MozWebSocket(webSocketUrl);
		console.log("建立实时连接！");
	} else {
		alert("浏览器不支持！");
	}
	webSocket2.onerror = function() {
		alert("无法建立实时连接！");
	};
	webSocket2.onopen = function(event) {
		send2();
		console.log("open");
	};
	webSocket2.onmessage = function() {
		if(event.data.length>2){
			livedata=event.data;
			//tableinitinfo();
			search();
			webSocket2.close();
		}else{
			console.log("resend...");
			send2();
		}		
	};
	webSocket2.onclose = function() {
	};
	window.onbeforeunload = function() {
		webSocket2.close();
	};
	function send2(){    //Websocket接口
	    console.log("send");
// 	    var message = "[{\"serialnum\":\"all\",\"signalnames\":[\"breakerstate\",\"runninglight\",\"faultlight\"]}]";//调用参数
	    var message = "[{\"serialnum\":\"all\",\"signalnames\":[\"c196\",\"c78\",\"c77\"]}]";//调用参数
	    webSocket2.send(message);
	}
</script>
</html>
